<template>
    <div>
        <b-alert variant="primary" show class="mt-20px text-center">
            请核实您的身份:{{ user_info }}
        </b-alert>
        <b-card class="mt-20px text-1em" title="领导干部综合测评投票须知:" border-variant="primary" header-bg-variant="primary">
            <b-card-text></b-card-text>
            <b-card-text>1.参加测评人员通过微信扫描二维码，即可测评，每个二维码唯一，不可复投，代投。</b-card-text>
            <b-card-text>2.测评为匿名，请参评人员如实、客观、公正做出评价。</b-card-text>
            <b-card-text>3.请组织单位人员在系统测评期内测评，过期无效。</b-card-text>
            <b-card-text>4.测评过程中有任何问题，请及时与我们联系。</b-card-text>
            <b-card-text>联系方式:</b-card-text>
            <b-card-text>杜潇宇:19991852008 屈甲康:18209262729</b-card-text>
            <b-card-text v-if="user_data.is_test > 0">
                <b-badge variant="warning">当前投票是测试票，不计入最终结果</b-badge>
            </b-card-text>

        </b-card>
        <b-button block :variant="disableCheck ? 'outline-secondary' : 'primary'" :disabled="disableCheck" size="lg"
            @click="goHome" class="mt-20px">已核实</b-button>
    </div>
</template>
<script>
import { CheckUserApi } from '../../api/mobile/check-user';
const api = new CheckUserApi;
export default {
    name: "CheckUser",
    data() {
        return {
            user_info: "",
            user_data: {},
            code: this.$route.query.code,
            name: this.$route.query.name
        }
    },
    async mounted() {
        const { project_id, project_owner_id, name } = this.$route.query;
        const user_data = await api.checkUserCode({ project_id, project_owner_id, name });
        this.user_data = user_data;
        this.user_info = user_data['group_name'] + ':' + user_data['name'] + '(' + user_data['remark'] + ')';
        if (this.user_data.message) {
            this.$toast.warning(this.user_data.message, { duration: 3000 });
            return;
        }
        if (this.user_data.is_login > 0 || this.user_data.is_submit > 0) {
            this.$router.push({ name: 'vote-ed' })
        }
    },
    methods: {
        async goHome() {
            if (this.user_data.code === this.code) {
                const { project_id, project_owner_id } = this.$route.query;
                this.$router.push({ name: "mobile-vote-home", query: { project_id, project_owner_id, name: this.name, code: this.code, is_test: this.user_data.is_test } });
            } else {
                this.$toast.error("身份信息错误，请扫描正确的二维码");
            }
        }
    },
    computed: {
        disableCheck() {
            return Boolean(this.user_data.message)
        }
    }
}
</script>